package com.service.admin.financial.service.impl;

import com.service.admin.financial.controller.dto.rep.FinancialReportRep;
import com.service.admin.financial.service.FinancialReportService;
import com.service.admin.member.service.MemberJAService;
import com.service.admin.member.service.MemberStoreService;
import com.service.admin.order.service.OrderProductHrComboService;
import com.service.dao.enums.CoinsEnum;
import com.service.dao.enums.MemberJAType;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;


/**
 * 财务报告接口实现
 *
 * @author 404notfound
 * @since 2021年05月16日10:42:32
 */
@Service
public class FinancialReportServiceImpl implements FinancialReportService {

    /**
     * 充提接口
     */
    @Autowired
    private OrderProductHrComboService orderProductHrComboService;

    @Autowired
    private MemberJAService memberJAService;

    @Autowired
    private MemberStoreService memberStoreService;

    /**
     * 查询财务信息
     *
     * @return
     */
    @Override
    public FinancialReportRep info() {

        //查询今日充值数量
        Date current = new Date();
        String currentStr = DateFormatUtils.format(current, DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.getPattern());

        //今日充值记录
        BigDecimal totalTodayRechargeNum = memberJAService.totalStatementByParam(currentStr, MemberJAType.getRechargeType());
        //统计历史累计充值数量
        BigDecimal totalHistoryRechargeNum = memberJAService.totalStatementByParam(null, MemberJAType.getRechargeType());


        //统计今日提币
        BigDecimal totalTodayWithdrawNum = memberJAService.totalStatementByParam(currentStr, MemberJAType.getWithdrawType());
        //统计累计提币
        BigDecimal totalHistoryWithdrawNum = memberJAService.totalStatementByParam(null, MemberJAType.getWithdrawType());

        //统计今日产币
        BigDecimal totalTodayMiningOutPutNum = memberJAService.totalStatementByParam(currentStr, MemberJAType.getMiningOutPutType());
        //统计累计产币
        BigDecimal totalHistoryMiningOutPutNum = memberJAService.totalStatementByParam(null, MemberJAType.getMiningOutPutType());

        //购买类型状态
        List<Integer> orderStatus = new ArrayList<>(Arrays.asList(1, 2));
        //统计今日购买
        BigDecimal totalTodayHashRate = orderProductHrComboService.totalStatementByParam(currentStr, orderStatus);
        //统计累计购买
        BigDecimal totalHistoryHashRate = orderProductHrComboService.totalStatementByParam(null, orderStatus);

        //流通资产
        BigDecimal totalUSDT = memberStoreService.totalStatementByParam(CoinsEnum.USDT.getName());
        BigDecimal totalBTC = memberStoreService.totalStatementByParam(CoinsEnum.BTC.getName());
        BigDecimal totalETH = memberStoreService.totalStatementByParam(CoinsEnum.ETH.getName());
        BigDecimal totalFIL = memberStoreService.totalStatementByParam(CoinsEnum.FIL.getName());

        return FinancialReportRep.builder()
                .totalTodayRechargeNum(totalTodayRechargeNum)
                .totalHistoryRechargeNum(totalHistoryRechargeNum)
                .totalTodayWithdrawNum(totalTodayWithdrawNum)
                .totalHistoryWithdrawNum(totalHistoryWithdrawNum)
                .totalTodayMiningOutPutNum(totalTodayMiningOutPutNum)
                .totalHistoryMiningOutPutNum(totalHistoryMiningOutPutNum)
                .totalTodayHashRate(totalTodayHashRate)
                .totalHistoryHashRate(totalHistoryHashRate)
                .totalUSDT(totalUSDT)
                .totalBTC(totalBTC)
                .totalETH(totalETH)
                .totalFIL(totalFIL).build();

    }
}


















